/**
 * 
 */
package com.alstudio.ui.module.economy;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.module.xmpp.request.ALUiXmppRequestCreator;
import com.alstudio.pojo.ALXmppEvent;
import com.alstudio.ui.base.TitleBarActivity;
import com.alstudio.utils.log.ALLog;
import com.loovee.imaohu.R;

/**
 * 我的钱包
 * 
 * @author alonso lee
 * 
 */
public class UserWalletActivity extends TitleBarActivity {

	private MyWalletView myWalletView;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.TitleBarActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setupView(this, getClass().getSimpleName());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#setupView(android.content.Context,
	 * java.lang.String)
	 */
	@Override
	protected void setupView(Context context, String name) {
		// TODO Auto-generated method stub
		super.setupView(context, name);
		setCenterTextViewMessage(R.string.TxtUserWallet);
		// MyWalletView
		myWalletView = new MyWalletView(context);
		setTitleBarContentView(myWalletView);
		myWalletView.setUserGold(ALLocalEnv.getLocalEnv().getMyProfile()
				.getGold());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#initData()
	 */
	@Override
	protected void initData() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#onResume()
	 */
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// 请求价格
		ALUiXmppRequestCreator
				.postALUiXmppGetRechargePrice(ALUiXmppRequestCreator.REQUEST_RECHARGE_TYPE_RMB);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.ui.base.BaseActivity#handleGetRechargePriceEvent(com.alstudio
	 * .pojo.ALXmppEvent)
	 */
	@Override
	public void handleGetRechargePriceEvent(ALXmppEvent data) {
		// TODO Auto-generated method stub
		super.handleGetRechargePriceEvent(data);
		if (data.getResponseCode() == ALXmppEvent.RESPONSE_OK) {
			String gold = data.getStrData1();
			ALLog.d("我的余额" + gold);
			if (!TextUtils.isEmpty(gold)) {
				ALLocalEnv.getLocalEnv().getMyProfile().setGold(gold);
				myWalletView.setUserGold(ALLocalEnv.getLocalEnv()
						.getMyProfile().getGold());
			}
		}
	}

}
